<?php
/**
 * Albireo Desktop
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Webtop
 */

namespace ApplicationsModule\PreferencesModule;

use Nette\Debug;

use WebtopModule\BasePresenter;
use ApplicationsModule\PreferencesModule\DesktopPreferencesManagement;
use Nette\Forms\SubmitButton;
use Albireo\Forms\AlbireoForm;

final class DesktopPreferencesPresenter extends BasePresenter {
    private $databaseManagement = null;

    /*
     * UNFINISHED (database connection)
     */
    public function startup() {
	parent::startup();
	$this->databaseManagement = new DesktopPreferencesManagement();
    }

    public function createComponentForm() {
        $iconSizes = array('small', 'medium', 'large', 'extra large');
        $backroundStyles = array('center', 'stretch');
        
        $defaultValues = $this->databaseManagement->getPreferences();

	$form = new AlbireoForm($this,'form');

        $form->addSelect('iconsSize', 'Icons Size:' , $iconSizes)->setDefaultValue($defaultValues['iconsSize']);
	$form->addSelect('backroundStyle', 'Backround Style:' , $backroundStyles)->setDefaultValue($defaultValues['backroundStyle']);
        $form->setDefaults($defaultValues);
        $form->addSubmit('save', 'Save')->onClick[] = array($this, 'saveClicked');
	$form->addSubmit('back', 'Back')->setValidationScope(FALSE)->onClick[] = array($this, 'backClicked');

	return $form;
    }

    public function saveClicked(SubmitButton $button) {
        $values = $button->getForm()->getValues();
        Debug::dump($values);
	try {
            $this->databaseManagement->setPreferences($values);
	}
	catch(DibiException $exception) {
		    
	}
	$this->redirect('desktopPreferences:default');
    }

    public function backClicked(SubmitButton $button) {
        $this->redirect('preferences:default');
    }

    public function actionDefault() {

    }

    public function renderDefault() {
	$this->template->form = $this['form'];
    }
}